#!/usr/bin/env python
"multiprocessing模块基本操作"

from multiprocessing import Process, Lock
import os


def who_am_i(label_str, lock):
	"打印信息"
	msg_str = '{}: name={} process={}'.format(label_str, __name__, os.getpid())
	with lock:
		print(msg_str)


def main():
	lock = Lock()
	who_am_i('function call', lock)

	process = Process(target=who_am_i, args=('spawned child', lock))
	process.start()
	process.join()

	for i_id_int in range(5):
		Process(
			target=who_am_i, 
			args=('run process {}'.format(i_id_int), lock)
		).start()

	with lock:
		print('Main process exit')


if __name__ == '__main__':
	main()
